package pl.edu.pw.perg.compinfodb.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Restrictions;

import pl.edu.pw.perg.compinfodb.entities.ElementType;
import pl.edu.pw.perg.compinfodb.entities.PhysicalElement;

public class PhysicalElementDAO extends GenericSpringDAO<PhysicalElement> implements IPhysicalElementDAO{

  @Override
  public void deleteAll() {
	SQLQuery sqlq = getSession().createSQLQuery("delete from Attribute");
	sqlq.executeUpdate();
    Query q = getSession().createQuery("delete from PhysicalElement"); 
    q.executeUpdate();
  }

public List<PhysicalElement> findElementsByType(ElementType type) {
//	Query q = getSession().createSQLQuery("select * from physical_element where element_type_id = ?").setLong(0, type.getId()); 
//    return q.list();
	return findByCriteria( Restrictions.eq("elementType", type));
}

public List<PhysicalElement> findSpareElements() {
	return findByCriteria( Expression.isNull("virtualElement"));
}
}
